//
//  ZZPUtils.m
//  TeachingAssistants
//
//  Created by 张志鹏 on 16/10/20.
//  Copyright © 2016年 ZhangZhipeng. All rights reserved.
//

#import "ZZPUtils.h"
#import "MBProgressHUD.h"

@implementation ZZPUtils
+(NSString*)handleNullString:(id)m_result{
    if(m_result==nil){
        return @"";
    }
    if([m_result isEqual:[NSNull null]]){
        return @"";
    }
    if([[NSString stringWithFormat:@"%@",m_result] isEqualToString:@"(null)"]){
        return @"";
    }
    return [NSString stringWithFormat:@"%@",m_result];
}


// 获取当前视图控制器
+ (UIViewController *)activityViewController
{
    UIViewController* activityViewController = nil;
    
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    if(window.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow *tmpWin in windows)
        {
            if(tmpWin.windowLevel == UIWindowLevelNormal)
            {
                window = tmpWin;
                break;
            }
        }
    }
    
    NSArray *viewsArray = [window subviews];
    if([viewsArray count] > 0)
    {
        UIView *frontView = [viewsArray objectAtIndex:0];
        
        id nextResponder = [frontView nextResponder];
        
        if([nextResponder isKindOfClass:[UIViewController class]])
        {
            activityViewController = nextResponder;
        }
        else
        {
            activityViewController = window.rootViewController;
        }
    }
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    if (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
        return topVC;
    }
    
    return activityViewController;
}

//+ (void)showWarning:(NSString *)message {
//    [MBProgressHUD Message:message For:[ZZPUtils activityViewController].view yOffset:-130.f];
//}
//存储用户信息
+ (void)saveUserDefultsData:(id)data forKey:(NSString *)key {
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
// 读取用户信息
+ (id)readUserDefultsDataForKey:(NSString *)key {
    id obj = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return obj;
}
// 删除用户偏好设置
+ (void)removeUserDefultsDataForkey:(NSString *)key {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


// 获取时间戳

+(NSString *)getTimeStamp
{
    
    NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
    long long int date = (long long int)time;
    return [NSString stringWithFormat:@"%lld",date];
}


+ (NSString *)updateTimeStamp:(NSString *)stmp {
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    return  [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[stmp floatValue]/1000]];
}


+(void)timeCuterWithSuper:(UIButton *)codeBtn AndoverBlock:(void (^)())runLoperBlock{

    __block int timeout=59;
    //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0);// 每秒执行
    
    dispatch_source_set_event_handler(_timer, ^{
        
        if(timeout<=0){ //倒计时结束，关闭
            
            dispatch_source_cancel(_timer);
            
            dispatch_async(dispatch_get_main_queue(), ^{                 runLoperBlock();
            });
            
        }else{
            
            
            int seconds = timeout % 61;
            
            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                // 设置界面的按钮显示 根据自己需求设置
                [codeBtn setTitle:[NSString stringWithFormat:@"重试(%@s)",strTime] forState:UIControlStateNormal];
                
            });
            
            timeout--;
            
        }
        
    });
    
    dispatch_resume(_timer);
    
}

/**
 *  判断字符串是否为空
 */
+ (BOOL)isBlankString:(NSString *)string {
    
    if (string == nil || string == NULL) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if ([string isKindOfClass:[NSDictionary class]]) {
        return YES;
    }
    if ([string isKindOfClass:[NSString class]] == NO) {
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
        return YES;
    }
    if ([string isEqualToString:@""]) {
        return YES;
    }
    return NO;
}




+ (void)showWarning:(NSString *)message {

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[ZZPUtils activityViewController].view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.tag = 100;
    hud.label.text = message;
    hud.label.numberOfLines = 2;
    hud.label.font = [UIFont systemFontOfSize:14];
//    hud.yOffset = y;
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:2];
}


+ (NSMutableDictionary *)delteNullDataWithDic:(NSDictionary *)dataDic {
    NSMutableDictionary *resultDic = [[NSMutableDictionary alloc]initWithDictionary:dataDic];
    for (NSString *key in resultDic.allKeys) {
        if ([[resultDic objectForKey:key] isEqual:[NSNull null]]) {
            [resultDic setValue:@"" forKey:key];
        }
    }
    return resultDic;
}
//date转时间
+(NSString *)getTimeFromShortTimeDa:(NSDate *)date{
    
    NSDateFormatter *objDateformat = [[NSDateFormatter alloc] init];
    [objDateformat setDateFormat:@"yyyy-MM-dd"];
    NSString * timeStampString = [objDateformat stringFromDate: date];
    return timeStampString;
    
}

+ (NSMutableString *)sortString:(NSMutableString *)srcStr
{
    NSInteger len = [srcStr length];
    for (NSInteger i=0; i<len-1; i++) {
        for (NSInteger j=0; j<len-i-1; j++) {
            unichar ch1 = [srcStr characterAtIndex:j];
            unichar ch2 = [srcStr characterAtIndex:j+1];
            if (ch1 > ch2) {
                srcStr = [NSMutableString stringWithFormat:@"%@",[srcStr stringByReplacingCharactersInRange:NSMakeRange(j, 1) withString:[NSMutableString stringWithFormat:@"%C", ch2]]];
                srcStr = [NSMutableString stringWithFormat:@"%@",[srcStr stringByReplacingCharactersInRange:NSMakeRange(j+1, 1) withString:[NSString stringWithFormat:@"%C", ch1]]];
            }
        }
    }
    return srcStr;
}




+(void)setBool:(NSString *)keyname andValue:(BOOL)value
{
    [[NSUserDefaults standardUserDefaults] setBool:value forKey:keyname];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+(BOOL)getBool:(NSString *)keyname
{
    return [[NSUserDefaults standardUserDefaults] boolForKey:keyname];
}


+ (BOOL)isPhotographer {
//    if ([ZZPUtils readUserDefultsDataForKey:@"userStatus"]== nil) {
//        SplashViewController *spl = [[SplashViewController alloc] init];
//        [[self activityViewController] presentViewController:spl animated:YES completion:nil];
//    }else
    
        if ([[ZZPUtils readUserDefultsDataForKey:@"userStatus"] isEqualToString:@"Photographer"]) {
        return YES;
    }
    return NO;
}



+ (void)addShowToView:(UIView *)view{
    view.layer.cornerRadius = 4;
    view.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    view.layer.shadowOffset = CGSizeMake(2, 3);
    view.layer.shadowOpacity = 0.3;
    view.layer.shadowRadius = 4;
}


//拨打电话
+(void)telephoneForAppWithNum:(NSString *)telephone{
    
    if(telephone.length==0){
        
        return;
    }
    
//    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephone];
//    IMYWebView * callWebview = [[IMYWebView alloc] init];
//    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
//    [[ZZPUtils activityViewController].view addSubview:callWebview];
    
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephone];
    UIApplication *application = [UIApplication sharedApplication];
    NSURL *URL = [NSURL URLWithString:str];
    [application openURL:URL options:@{} completionHandler:^(BOOL success) {
        //OpenSuccess=选择 呼叫 为 1  选择 取消 为0
        NSLog(@"OpenSuccess=%d",success);
        
    }];
    
}


//删除线
+ (void)deleteLineLabel:(UILabel *)oldPriceLabel {
    NSUInteger length = [oldPriceLabel.text length];
    
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:oldPriceLabel.text];
    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, length)];
    [attri addAttributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),NSBaselineOffsetAttributeName:@(0)} range:NSMakeRange(0, length)];
    [oldPriceLabel setAttributedText:attri];
}


+ (NSString *)updateTimeStamp:(NSString *)stmp andType:(NSString *)type{
    if(stmp.length == 0){
        return @"";
    }
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setDateFormat:type];
    
    return  [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[stmp floatValue]/1000]];
}

+(id)jsonToObject:(NSString *)json
{
    NSError *error;
    id obj =[NSJSONSerialization JSONObjectWithData:[json dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];
    if (error) {
        obj = nil;
    }
    return obj;
}

+ (void)showAlertViewWithView:(UIView *)view andController:(UIViewController *)controller {
    SPAlertController *alertController = [SPAlertController alertControllerWithCustomAlertView:view preferredStyle:SPAlertControllerStyleAlert animationType:SPAlertAnimationTypeDefault];
      alertController.minDistanceToEdges = 25;
      [controller presentViewController:alertController animated:YES completion:nil];
}

+ (void)showActionSheetWithView:(UIView *)view andController:(UIViewController *)controller {
    
    SPAlertController *alertController = [SPAlertController alertControllerWithCustomAlertView:view preferredStyle:SPAlertControllerStyleActionSheet animationType:SPAlertAnimationTypeDefault];
    [controller presentViewController:alertController animated:YES completion:nil];
}


+ (void)presentLoginViewController:(UIViewController *)con {
    LoginViewController *login = [[LoginViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:login];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [con presentViewController:nav animated:YES completion:nil];
}

+ (void)aliLoginWithController:(UIViewController *)con andResulBlock:(ResultBlock)reslultBolck{
//    [[TXCommonHandler sharedInstance] setAuthSDKInfo:@"EZAGC1/IDz5iYTs0x5X0G7HRJCc9XADqmFb3QBTkNPuSUIFrOZq8BLbvr0lr1BhE46+XOZi0ebQfj2Lz6nUb/UZB/GYmmGOlCvFK7XFvnyL+PZDdqJG64BiQEC+9SoZlQEu/AQQLutNdc2xPxRuSOiqnfO7vwMnzz1kxV78KLwYQm0xpUqbHFQjGFrFOUpqfVs02x8UQ2ienI/hYPIpPb38KolPss692BGd3MlmgZFAyhKUMhUcKsvDpwEI2Q7/U" complete:^(NSDictionary * _Nonnull resultDic) {
//
//              NSLog(@"resultDic:%@",resultDic);
//
//              [[TXCommonHandler sharedInstance] accelerateLoginPageWithTimeout:3.0 complete:^(NSDictionary * _Nonnull resultDic) {
//                    NSLog(@"==============resultDic:%@",resultDic);
//                  
//                  TXCustomModel *model = [[TXCustomModel alloc] init]; //默认，注：model的构建需要放在主线程
//                     model.navColor = [UIColor whiteColor];
//                  model.navTitle = [[NSMutableAttributedString alloc] initWithString:@"总角读书会" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 17],NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]}];
//                     model.logoImage = [UIImage imageNamed:@"logo"];
//                  model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
//                      frame.size.width = 76;
//                      frame.size.height = 76;
//                      frame.origin.x = (ScreenWidth-76)/2;
//                      frame.origin.y = 110;
//                      return frame;
//                  };
//                
//                  model.numberColor = rgba(51, 51, 51, 1.0);
//                  
//                    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"选择登录方式" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 25],NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]}];
//                     model.sloganText = string;
//                  
//                  model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
//                      
//                             frame.origin.y = 30;
//                             return frame;
//                     };
//                  
//                  model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
//                      frame.size.width = ScreenWidth-32*2;
//                      frame.origin.x = 32;
//                      frame.size.height = 44;
//                      return frame;
//                  };
//                  
//                  model.loginBtnBgImgs = @[LocalImagePath(@"登录按钮底"),LocalImagePath(@"登录按钮底"),LocalImagePath(@"登录按钮底")];
//                     
//                    model.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"其他登录方式" attributes:@{NSForegroundColorAttributeName : mainColor,NSFontAttributeName : [UIFont systemFontOfSize:17.0]}];
//                  
//                  model.changeBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
//                      frame.origin.y = frame.origin.y-25;
//                      return frame;
//                  };
//                     model.privacyAlignment = NSTextAlignmentCenter;
//                  model.privacyOne = @[@"《用户协议》",[NSString stringWithFormat:@"%@/zjReadClue/#/pages/index/xieyi?type=10002",ADDRESSIP]];
//                      model.privacyTwo = @[@"《隐私条款》",[NSString stringWithFormat:@"%@/zjReadClue/#/pages/index/xieyi?type=10000",ADDRESSIP]];
//                  model.privacyColors = @[mainColor,mainColor];
//                  model.checkBoxImages = @[LocalImagePath(@"会员未选中"),LocalImagePath(@"会员选中")];
//                  model.checkBoxIsChecked = YES;
//                  
//                   //直接调用获取登录Token接口，内部会先去取号，取号成功之后再弹授权页，所以能感觉到弹起有一个延迟
//                    [[TXCommonHandler sharedInstance] getLoginTokenWithTimeout:0 controller:con model:model complete:^(NSDictionary * _Nonnull resultDic) {
//                        //注意回调线程
//                        NSString *code = [resultDic objectForKey:@"resultCode"];
//                        if ([PNSCodeLoginControllerPresentSuccess isEqualToString:code]) {
////                            [ZZPUtils showWarning:@"弹起授权页成功"];
//                        } else if ([PNSCodeLoginControllerClickCancel isEqualToString:code]) {
////                            [ZZPUtils showWarning:@"点击了授权页的返回"];
//                        } else if ([PNSCodeLoginControllerClickChangeBtn isEqualToString:code]) {
////                            [ZZPUtils showWarning:@"点击切换其他登录方式按钮"];
//                            
//                            dispatch_async(dispatch_get_main_queue(), ^{
//                                [[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:^{
////                                    LoginViewController *login = [[LoginViewController alloc] init];
////                                    login.hidesBottomBarWhenPushed = YES;
////                                    [con.navigationController pushViewController:login animated:YES];
//                                }];
//                            }) ;
//                            
//                            
//
//                            
//                        } else if ([PNSCodeLoginControllerClickLoginBtn isEqualToString:code]) {
//                            if ([[resultDic objectForKey:@"isChecked"] boolValue] == YES) {
////                                [ZZPUtils showWarning:@"点击了登录按钮，check box选中，SDK内部接着会去获取登陆Token"];
//                            } else {
////                                [ZZPUtils showWarning:@"点击了登录按钮，check box未选中，SDK内部不会去获取登陆Token"];
//                            }
//                        } else if ([PNSCodeLoginControllerClickCheckBoxBtn isEqualToString:code]) {
////                            [ZZPUtils showWarning:@"点击check box"];
//                        } else if ([PNSCodeLoginControllerClickProtocol isEqualToString:code]) {
////                            [ZZPUtils showWarning:@"点击了协议富文本"];
//                        } else if ([PNSCodeSuccess isEqualToString:code]) {
//                            //点击登录按钮获取登录Token成功回调
//                            NSString *token = [resultDic objectForKey:@"token"];
//                             if (!token || token.length == 0) {
//                                [ZZPUtils showWarning:@"token无效"];
//                                 
//                                 dispatch_async(dispatch_get_main_queue(), ^{
//                                     [[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:nil];
//                                 }) ;
//                                 
//                                return;
//                            }
//                      
//                            NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
//                            [paraDic setValue:token forKey:@"token"];
//                            
//                            
//                            [[ZZPRequest getWebUtil] postNetworkRequestURLString:@"/ZjReadingClub/api/login" andParas:paraDic andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
//                                if (!error) {
//                                    NSLog(@"用户信息：%@",info);
//                                    
//                                    [ZZPUtils saveUserDefultsData:[ZZPUtils deleteEmpty:info] forKey:@"userInfo"];
//                                    [con dismissViewControllerAnimated:YES completion:nil];
//                                    
//                                    reslultBolck(YES);
//                                    
//                                }
//                                
//                                
//                                dispatch_async(dispatch_get_main_queue(), ^{
//                                    [[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:nil];
//                                }) ;
//                                
//                                
//                                
//                            }];
//                            
//                            
//                        } else {
////                            [ZZPUtils showWarning:@"获取登录Token失败"];
//                            
//                            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"要想使用此功能请先开启移动网络" preferredStyle:UIAlertControllerStyleAlert];
//                            UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
//                            [alert addAction:action];
//                            [con presentViewController:alert animated:YES completion:nil];
//                            
//                            
//                        }
//                
//                    }];
//                }];
//          }];
}



+ (void)setLineSpace:(CGFloat)lineSpace withText:(NSString *)text inLabel:(UILabel *)label{
    if (!text || !label) {
        return;
    }
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = lineSpace;  //设置行间距
    paragraphStyle.lineBreakMode = label.lineBreakMode;
    paragraphStyle.alignment = label.textAlignment;
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    label.attributedText = attributedString;
}




+ (void)loginToRongCloud{
    
//    if([GetHandleString(USERINFO, @"imToken") length] > 0){
//        
//        [[RCIMClient sharedRCIMClient] disconnect:NO];
//        
//        
//        [RCIM sharedRCIM].enablePersistentUserInfoCache = YES;
//        
//        RCKitConfigCenter.message.enableSyncReadStatus = YES;
//        RCKitConfigCenter.message.isMediaSelectorContainVideo = YES;
//        RCKitConfigCenter.message.enableSendCombineMessage = YES;
//        RCKitConfigCenter.message.reeditDuration = YES;
//        RCKitConfigCenter.message.enableMessageResend = YES;
//        RCKitConfigCenter.message.reeditDuration = YES;
//        
//        RCKitConfigCenter.ui.globalConversationPortraitSize = CGSizeMake(44, 44);
//        
//        RCKitConfigCenter.ui.globalNavigationBarTintColor = [UIColor whiteColor];
//        
//        
//        RCUserInfo *user = [[RCUserInfo alloc] initWithUserId:GetHandleString(USERINFO, @"imId") name:GetHandleString(USERINFO, @"nickName") portrait:GetHandleString(USERINFO, @"avatar")];
//
//        [[RCIM sharedRCIM] refreshUserInfoCache:user withUserId:user.userId];
////
//        
//        [[RCIM sharedRCIM] connectWithToken:GetHandleString(USERINFO, @"imToken") dbOpened:^(RCDBErrorCode code) {
//            //消息数据库打开，可以进入到主页面
//            NSLog(@"消息数据库打开，可以进入到主页面");
//        }success:^(NSString *userId) {
//            //连接成功,可跳转至会话列表页
//            NSLog(@"连接成功,可跳转至会话列表页");
//        }error:^(RCConnectErrorCode status) {
//            if (status == RC_CONN_TOKEN_INCORRECT) {
//                //从 APP 服务获取新 token，并重连
//                NSLog(@"从 APP 服务获取新 token，并重连");
//            } else {
//                //无法连接到 IM 服务器，请根据相应的错误码作出对应处理
//                NSLog(@"无法连接到 IM 服务器，请根据相应的错误码作出对应处理");
//            }
//        }];
//    }
    
}


+ (NSString *)dataToJasonString:(id)theData{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSLog(@"jsonString: %@", jsonString);
    return jsonString;
}

+ (id)toArrayOrNSDictionary:(NSString *)str{
    NSData *jsonData = [str dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
    if (jsonObject != nil && error == nil){
        return jsonObject;
    }else{
        // 解析错误
        return nil;
    }
}


//获取当前时间戳 （以毫秒为单位）
+(NSString *)getNowTimeTimestamp{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss SSS"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    //设置时区,这个对于时间的处理有时很重要
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]*1000];
    return timeSp;
}


+ (NSString *)numToString:(NSInteger)inter{
    NSNumberFormatter  *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = kCFNumberFormatterRoundHalfDown;
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_Hans"];
    formatter.locale = locale;
    NSString *ch_string = [formatter stringFromNumber:[NSNumber numberWithInteger:inter]];
    return ch_string;
}





@end
